package pat;

import java.util.Scanner;

public class B1018 {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        int num = input.nextInt();
        char data[][] = new char[num][2];
        int result[][] = new int[3][2];

        for (int i = 0; i < num; i++) {
            data[i][0] = input.next().charAt(0);
            data[i][1] = input.next().charAt(0);
        }

        for (char game[] : data) {
            if ((game[0] == 'B') && (game[1] == 'C')) {
                result[0][0]++;
            }
            if ((game[0] == 'B') && (game[1] == 'J')) {
                result[2][1]++;
            }
            if ((game[0] == 'C') && (game[1] == 'B')) {
                result[0][1]++;
            }
            if ((game[0] == 'C') && (game[1] == 'J')) {
                result[1][0]++;
            }
            if ((game[0] == 'J') && (game[1] == 'B')) {
                result[2][0]++;
            }
            if ((game[0] == 'J') && (game[1] == 'C')) {
                result[1][1]++;
            }
        }

        int win = result[0][0] + result[1][0] + result[2][0];
        int lose = result[0][1] + result[1][1] + result[2][1];
        int same = num - win - lose;

        System.out.println(win + " " + same + " " + lose);
        System.out.println(lose + " " + same + " " + win);

        int indexj = -1;
        int maxj = -1;
        int indexy = -1;
        int maxy = -1;

        for (int i = 0; i < 3; i++) {
            if (result[i][0] > maxj) {
                maxj = result[i][0];
                indexj = i;
            }
            if (result[i][1] > maxy) {
                maxy = result[i][1];
                indexy = i;
            }
        }

        char chj = '0';
        char chy = '0';

        if (indexj == 0) {
            chj = 'B';
        } else if (indexj == 1) {
            chj = 'C';
        } else {
            chj = 'J';
        }

        if (indexy == 0) {
            chy = 'B';
        } else if (indexy == 1) {
            chy = 'C';
        } else {
            chy = 'J';
        }

        System.out.println(chj + " " + chy);

    }
}